home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Storage / IAMutex.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  1.5 KB  |  55 lines  |  [TEXT/CWIE]

  1. // IAMutex.h
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4.  
  5. // Interface to mutexes (MUtual EXclusion semaphors) used by IA library.
  6. // Applications simply subclass IAMutex and set IANewMutex
  7. // to make IA code thread-safe for the application's threads.
  8.  
  9. #pragma once
  10. #ifndef IAMutex_h
  11. #define IAMutex_h
  12.  
  13. #pragma import on
  14.  
  15. #include "IACommon.h"
  16.  
  17. //#pragma IA_BEGIN_IMPORTS
  18. #include <stdlib.h>
  19. //#pragma IA_END_IMPORTS
  20.  
  21. #pragma IA_BEGIN_EXPORTS
  22.  
  23. class IAMutex {                                    // base class for mutexes
  24. public:
  25.     virtual            ~IAMutex();                    // no-op
  26.     virtual void    Lock() = 0;                    // returns when we have control of the mutex
  27.     virtual void    Unlock() = 0;                // releases control of the mutex
  28. };
  29.  
  30. typedef IAMutex*            IAMutexConstructor();
  31. IAMutex*                    IADefaultMutexConstructor();    // no-op mutex implementation
  32.  
  33. // IANewMutex is used by IA code to create new mutexes.
  34. // Applications should reset this to use a different mutex implementation.
  35. // By default it is set to &IADefaultMutexConstructor, appropriate for single-threaded apps.
  36. extern IAMutexConstructor*    IANewMutex;
  37.  
  38. // Locks a mutex for the duration of its stack-allocated life.
  39. // The typical usage is:
  40. //   { IALock lock(mutex);
  41. //     ... code that needs to run locked ... }
  42. class IALock {
  43. public:
  44.     IALock(IAMutex* mutex);                        // locks the mutex
  45.     ~IALock(void);                                // unlocks the mutex
  46. private:
  47.     IAMutex            *mutex;
  48.     void*            operator new(size_t size);    // stack allocate only
  49. };
  50.  
  51. #pragma IA_END_EXPORTS
  52.  
  53. #pragma import reset
  54. #endif
  55.